﻿using RJi.FanucInterface3.Common.Enum;

namespace RJi.FanucInterface3.Common;

public static class IDataTableWrapperExtension
{
    /// <summary>
    ///     注册当前轴扭矩
    /// </summary>
    /// <param name="dataTableWrapper">数据表</param>
    /// <param name="count">注册轴的数量 1 ~ 9,默认值是 6</param>
    /// <param name="varType">系统变量的数据类型，默认使用 Real</param>
    /// <param name="key">注册时的 key</param>
    /// <returns></returns>
    /// <returns></returns>
    /// <exception cref="ArgumentOutOfRangeException"></exception>
    public static IDataTableWrapper RegisterAxisTorques(this IDataTableWrapper dataTableWrapper, short count = 6, SysVarType varType = SysVarType.Int,
        string key = "CUR_TORQUE")
    {
        switch (count)
        {
            case < 1:
                throw new ArgumentOutOfRangeException(nameof(count), "扭矩数量必须大于0");
            case > 9:
                throw new ArgumentOutOfRangeException(nameof(count), "扭矩数量必须小于10");
        }

        var sysVarNames = new string[count];

        for (var i = 0; i < count; i++) sysVarNames[i] = $"$MOR_GRP[1].$CUR_TORQUE[{i + 1}]";

        dataTableWrapper.RegisterSysVars(key, varType, sysVarNames);

        return dataTableWrapper;
    }
}